package cheme.ProcessEditor.Parts.ConsoleView;


import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.CompoundBorder;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.MouseEvent;
import org.eclipse.draw2d.MouseListener;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;

import cheme.ProcessEditor.Figures.ProcessUnitFig;
import cheme.ProcessEditor.Figures.SolvabilityStatusFig;
import cheme.ProcessEditor.Figures.Util.TitleFig;
import cheme.ProcessEditor.Policies.ContainerHighlightEditPolicy;
import cheme.ProcessEditor.Table.ListFig;
import cheme.ProcessModel.HelloModel;

public class HelloEditPart extends EditPartWithListener
{
	private MyDirectEditManager directManager = null;
	private IFigure fig;
	private ListFig listFig ;
	
	protected IFigure createFigure()
	{
		
		fig =  createFigureInternal();
		fig.addMouseListener(new MouseListener()
		{
			public void mouseDoubleClicked(MouseEvent me)
			{	
				System.out.print("Double Clicked");
			}

			public void mousePressed(MouseEvent me)
			{
			}

			public void mouseReleased(MouseEvent me)
			{
				System.out.println("mouseReleased");
			}
		});
		return fig;
	}
		
	protected IFigure createFigureInternal()
	{
		//HelloModel model = (HelloModel)getModel();

		listFig = new ListFig();		
		
		Label label = new Label();
		label.setText("Test label");

		label.setBorder(new CompoundBorder(new LineBorder(),
				new MarginBorder(3)));
				label.setBackgroundColor(ColorConstants.orange);

		label.setOpaque(true);
		listFig.add(label);
		
		Label lbl2 = new Label();
		lbl2.setText("22222");

		lbl2.setBorder(new CompoundBorder(new LineBorder(),
				new MarginBorder(3)));
		lbl2.setBackgroundColor(ColorConstants.green);

		lbl2.setOpaque(true);
		listFig.add(lbl2);

		return listFig;
	}
		
	protected void createEditPolicies()
	{
		installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new ContainerHighlightEditPolicy());
		
	}
	
	protected void refreshVisuals()
	{
		Rectangle constraint = ((HelloModel)getModel()).getConstraint();
		((GraphicalEditPart)getParent()).setLayoutConstraint(this, getFigure(),
				constraint);
	}
	
	protected void handleTextChange(PropertyChangeEvent evt)
	{
		List<IFigure> listOfchildren = new ArrayList<IFigure>();
		listOfchildren = listFig.getChildren();
		Label lbl = (Label)listOfchildren.get(0);
		lbl.setText("Text Changes");
		
	}

}
